package com.ddwl.goods.job;

import com.ddwl.goods.service.ItemService;
import com.ddwl.goods.service.LimitTimePurActiveService;
import com.ddwl.schema.bo.goods.ItemListBo;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class GoodsJob {

    @Resource
    public ItemService itemService;
    @Resource
    public LimitTimePurActiveService limitTimePurActiveService;

    /**
     * 开始更新商品佣金相关的数据订正任务
      * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("itemUpdateComission")
    public ReturnT<String> updateCommission(String param) throws Exception{
        XxlJobLogger.log("开始更新商品佣金相关的数据订正任务");
        itemService.updateCommission();
        return ReturnT.SUCCESS;
    }

    @XxlJob("itemUpdateOriginPrice")
    public ReturnT<String> itemUpdateOriginPrice(String param) throws Exception{
        XxlJobLogger.log("开始更新商品津贴价数据订正任务");
        itemService.updateOriginPrice();
        return ReturnT.SUCCESS;
    }

    @XxlJob("itemAuditingUpdate")
    public ReturnT<String> itemAuditingUpdate(String param) throws Exception{
        XxlJobLogger.log("商品二级审批数据订正");
        itemService.itemAuditingUpdate();
        return ReturnT.SUCCESS;
    }

    /**
     * 预售商品超时下架数据订正任务
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("recoverReserve")
    public ReturnT<String> recoverReserve(String param) throws Exception{
        XxlJobLogger.log("预售商品超时下架数据订正任务");
        itemService.recoverReserve();
        return ReturnT.SUCCESS;
    }

    /**
     * 发送零库存信息
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("sendZeroCountMessageJob")
    public ReturnT<String> sendZeroCountMessageHandle(String param) throws Exception{
        XxlJobLogger.log("开始发送零库存信息任务");
        ItemListBo bo=new ItemListBo();
        bo.setMaxStock(0);
        bo.setItemStatus(1);
        itemService.sendZeroCountMessage(bo);
        return ReturnT.SUCCESS;
    }

    /**
     * 限时购过期清理任务
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("updateOverActiveJob")
    public ReturnT<String> updateOverActiveHandle(String param) throws Exception{
        XxlJobLogger.log("start clean overtime limitTimeActive");
        limitTimePurActiveService.updateOverActive();
        return ReturnT.SUCCESS;
    }

}
